﻿using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PlaxoSyncWM;

namespace TestPlaxoSyncWM {
    [TestClass]
    public class TestPlaxoSync : BaseTest {
        private string editedContactsURL;
        private string exp;
        private PlaxoSync ps;

        [TestInitialize]
        public override void Setup() {
            base.Setup();

            ContactFixture.InMemory
                .WithContact("Kiran", "Bellubbi", "07940904211")
                .WithContact("Karen", "Bellubbi", "312-265-6852")
                .WithContact("Eugene", "DSouza", "07999900090")
                .CreateContacts();

            var mcf = new MobileContactsFile();
            if (!mcf.mobileContactsFileExists())
                mcf.create();

            var contacts = GetContacts();

            var contactIDs = new List<string>(from c in contacts select c.ItemId);
            //    new ArrayList();
            //contactIDs.Clear();
            //foreach (Contact c in collectionOfContacts)
            //{
            //    contactIDs.Add(c.ItemId.ToString());
            //}

            ps = new PlaxoSync();
            exp = "";
            exp =
                string.Format(
                    @"package=['Header', 'ProtoVer', '1', 'ClientID', 'PLXI:01000000000032497763030868604907', 'AuthMethod', 'Plaxo', 'Identifier', 'kiranbellubbi@gmail.com', 'Password', 'campion','Client', 'Dev Clientname/1.0', 'OS', 'windows/service pack infinity', 'Platform', 'Outlook/2005']%0a['Sync', 'Target', 'Contacts', 'Source', 'DevLocalContacts','LastAnchor', '0', 'NextAnchor', '1']%0a['Add', 'Type', 'Contact', 'ItemID', '{0}'], ['Data', 'AIMScreenName','', 'Birthday', '','BusinessEmail', '','BusinessIM', '','BusinessMicroBlog', '','BusinessMobilePhone', '', 'Category', '','Company', '', 'DisplayName', ' Karen  Bellubbi', 'FamilyName', ' Bellubbi','FirstName', ' Karen','HomeAddress', '', 'HomeCity', '','HomeCountry', '','HomeFax', '','HomePhone', '', 'HomeState', '','HomeZipCode', '','JobTitle', '','LastName', ' Bellubbi', 'MiddleName', '','NameSuffix', '','NameTitle', '','NickName', '','Notes', '', 'PersonalEmail', '', 'PersonalIM', '','PersonalMicroBlog', '','PersonalMobilePhone', ' 07940904211 ', 'PersonalPhoto', '','PersonalWebPage', '', 'PreferredAddress', '', 'WorkAddress', '', 'WorkCity', '','WorkCountry', '','WorkFax', '', 'WorkPager', '','WorkPhone', '', 'WorkState', '','WorkZipCode', '']%0a['Add', 'Type', 'Contact', 'ItemID', '{1}'], ['Data', 'AIMScreenName','', 'Birthday', '','BusinessEmail', '','BusinessIM', '','BusinessMicroBlog', '','BusinessMobilePhone', '', 'Category', '','Company', '', 'DisplayName', ' Kiran  Bellubbi', 'FamilyName', ' Bellubbi','FirstName', ' Kiran','HomeAddress', '', 'HomeCity', '','HomeCountry', '','HomeFax', '','HomePhone', '', 'HomeState', '','HomeZipCode', '','JobTitle', '','LastName', ' Bellubbi', 'MiddleName', '','NameSuffix', '','NameTitle', '','NickName', '','Notes', '', 'PersonalEmail', '', 'PersonalIM', '','PersonalMicroBlog', '','PersonalMobilePhone', ' 312-265-6852 ', 'PersonalPhoto', '','PersonalWebPage', '', 'PreferredAddress', '', 'WorkAddress', '', 'WorkCity', '','WorkCountry', '','WorkFax', '', 'WorkPager', '','WorkPhone', '', 'WorkState', '','WorkZipCode', '']%0a['Add', 'Type', 'Contact', 'ItemID', '{2}'], ['Data', 'AIMScreenName','', 'Birthday', '','BusinessEmail', '','BusinessIM', '','BusinessMicroBlog', '','BusinessMobilePhone', '', 'Category', '','Company', '', 'DisplayName', ' Eugene  Dsouza', 'FamilyName', ' Dsouza','FirstName', ' Eugene','HomeAddress', '', 'HomeCity', '','HomeCountry', '','HomeFax', '','HomePhone', '', 'HomeState', '','HomeZipCode', '','JobTitle', '','LastName', ' Dsouza', 'MiddleName', '','NameSuffix', '','NameTitle', '','NickName', '','Notes', '', 'PersonalEmail', '', 'PersonalIM', '','PersonalMicroBlog', '','PersonalMobilePhone', ' 07999900090 ', 'PersonalPhoto', '','PersonalWebPage', '', 'PreferredAddress', '', 'WorkAddress', '', 'WorkCity', '','WorkCountry', '','WorkFax', '', 'WorkPager', '','WorkPhone', '', 'WorkState', '','WorkZipCode', '']%0a['/Sync']",
                    contactIDs[0], contactIDs[1], contactIDs[2]);

            editedContactsURL = "";
            editedContactsURL =
                string.Format(
                    @"package=['Header', 'ProtoVer', '1', 'ClientID', 'PLXI:01000000000032497763030868604907', 'AuthMethod', 'Plaxo', 'Identifier', 'kiran.bellubbi@gmail.com', 'Password', 'campion','Client', 'Dev Clientname/1.0', 'OS', 'windows/service pack infinity', 'Platform', 'Outlook/2005']%0a['Sync', 'Target', 'Contacts', 'Source', 'DevLocalContacts','LastAnchor', '0', 'NextAnchor', '1']%0a['Add', 'Type', 'Contact', 'ItemID', '{0}'], ['Data', 'AIMScreenName','', 'Birthday', '','BusinessEmail', '','BusinessIM', '','BusinessMicroBlog', '','BusinessMobilePhone', '', 'Category', '','Company', '', 'DisplayName', 'Karen Bellubbi', 'FamilyName', 'Bellubbi','FirstName', 'Karen','HomeAddress', '', 'HomeCity', '','HomeCountry', '','HomeFax', '','HomePhone', '', 'HomeState', '','HomeZipCode', '','JobTitle', '','LastName', 'Bellubbi', 'MiddleName', '','NameSuffix', '','NameTitle', '','NickName', '','Notes', '', 'PersonalEmail', '', 'PersonalIM', '','PersonalMicroBlog', '','PersonalMobilePhone', '07940904212', 'PersonalPhoto', '','PersonalWebPage', '', 'PreferredAddress', '', 'WorkAddress', '', 'WorkCity', '','WorkCountry', '','WorkFax', '', 'WorkPager', '','WorkPhone', '', 'WorkState', '','WorkZipCode', '']%0a['/Sync']",
                    contactIDs[0]);
        }

        [TestMethod]
        public void testCreateURL() {
            Assert.IsNotNull(ps);
            
            Assert.AreEqual(exp, ps.createSlowAddUrl());
        }

        [TestMethod]
        public void testSlow() {
            Assert.IsTrue(ps.slow(ps.createSlowAddUrl()));
        }

        [TestMethod]
        public void testEditURL() {
            Assert.AreEqual(editedContactsURL, ps.createEditsOnDeviceUrl());
        }

        [TestMethod]
        public void testEditsToPlaxo() {
            Assert.IsTrue(ps.slow(ps.createEditsOnDeviceUrl()));
        }

        [TestMethod]
        public void testCreateAddsOnDeviceURL() {
            Assert.AreEqual("", ps.createAddsOnDeviceURL());
        }

        [TestMethod]
        public void testCreateDeletesOnDeviceURL() {
            Assert.AreEqual("", ps.createDeletesOnDeviceURL());
        }

        [TestMethod]
        public void testClearsContacts() {
            ContactFixture.InMemory
                .WithContact("Kiran", "Bellubi", "2222222")
                .CreateContacts();

            Assert.AreEqual(4, GetContacts().Count);

//            ClearContacts();

            //Assert.AreEqual(0, GetContacts().Count);
        }
    }
}